import QtQuick 2.6
import QtQuick.Layouts 1.2

import "../../Base/UiBase"
import "../../Base/Config"

import Data 1.0

import "../../FallView" as FallView
import "../../TCommunity/Post" as TCPost

Rectangle {
    id: root

    property string page: "fromMe" // "toMe" or "fromMe"

    color: Color.background

    MouseArea {
        z: -1
        anchors.fill: parent
    }

    ColumnLayout {
        anchors.fill: parent
        spacing: 0

        // header
        Rectangle {
            Layout.fillWidth: true
            Layout.preferredHeight: 96 * Size.ratio
            color: Color.foreground

            // back button
            ImageButton {
                width: 80 * Size.ratio
                height: 96 * Size.ratio
                anchors.left: parent.left
                anchors.verticalCenter: parent.verticalCenter
                source: "../../../resources/comment/fanhiu01.svg"

                onClicked: root.visible = false
            } // end back button

            Text {
                anchors.centerIn: parent
                text: qsTr("我的动态")
                color: Color.input
                font.pixelSize: Size.titleFont
            }
            BottomDivider {
            }
        } // end header

        // switcher
        Rectangle {
            Layout.fillWidth: true
            Layout.preferredHeight: 96 * Size.ratio
            color: Color.foreground
            RowLayout {
                anchors.fill: parent
                spacing: 0
                MouseArea {
                    onClicked: root.page = "fromMe"

                    Layout.fillWidth: true
                    Layout.fillHeight: true
                    Text {
                        anchors.centerIn: parent
                        font.pixelSize: Size.font32
                        color: root.page === "fromMe" ? Color.main : Color.input
                        text: qsTr("我发布的")
                    }
                    Rectangle {
                        width: parent.width
                        height: 5 * Size.ratio
                        anchors.bottom: parent.bottom
                        color: Color.main
                        visible: root.page === "fromMe"
                    }
                }
                MouseArea {
                    onClicked: root.page = "toMe"

                    Layout.fillWidth: true
                    Layout.fillHeight: true
                    Text {
                        anchors.centerIn: parent
                        font.pixelSize: Size.font32
                        color: root.page === "toMe" ? Color.main : Color.input
                        text: qsTr("与我相关")
                    }
                    Rectangle {
                        width: parent.width
                        height: 5 * Size.ratio
                        anchors.bottom: parent.bottom
                        color: Color.main
                        visible: root.page === "toMe"
                    }
                }
            }
        }

        // end switcher
        Item {
            Layout.fillWidth: true
            Layout.preferredHeight: 20 * Size.ratio
        }

        // body
        FallView.FallView {
            Layout.fillWidth: true
            Layout.fillHeight: true
            z: -1
            spacing: Size.elementInterval
            delegate: TCPost.AdvPost {
                width: parent.width
                username: model.username
                headSource: model.head
                subject: model.subject
                time: model.time
                location: model.location
                imageCount: model.imageCount
                imageSource: model.image
                commentText: model.comment
            }
            model: ListModel {
                id: listmodel
                Component.onCompleted: {
                    listmodel.append({
                                         username: "欢乐的0403",
                                         head: "../../../resources/tests/touxiang02.svg",
                                         subject: Subject.Music,
                                         time: new Date().toISOString(),
                                         location: "广西 来宾",
                                         imageCount: 1,
                                         image: "../../../resources/tests/121025539394.jpg",
                                         comment: "123123"
                                     })
                    listmodel.append({
                                         username: "欢乐的0403",
                                         head: "../../../resources/tests/touxiang02.svg",
                                         subject: Subject.Music,
                                         time: new Date().toISOString(),
                                         location: "广西 来宾",
                                         imageCount: 1,
                                         image: "../../../resources/tests/355X630.jpg",
                                         comment: "123123"
                                     })
                    listmodel.append({
                                         username: "欢乐的0403",
                                         head: "../../../resources/tests/touxiang02.svg",
                                         subject: Subject.Music,
                                         time: new Date().toISOString(),
                                         location: "广西 来宾",
                                         imageCount: 8,
                                         image: "../../../resources/tests/355X400.jpg",
                                         comment: "123123"
                                     })
                }
            }
        } // end body
    }
}
